import {reqHasResume,reqMatchResume,reqMyResume,reqResumeBaseInfo,reqResumeCoreInfo,reqAddResumeBaseInfo,reqAddResumeCoreInfo} from "@/api";

const state = {
  hasResume:false,
  matchResume:{},
  myResume:{},
  myBasicResume:{},
  myCoreResume:{},
  resumeId:""
}
const mutations={
  HASRESUME(state,hasResume){
    state.hasResume = hasResume
  },
  MATCHRESUME(state,matchResume){
    state.matchResume = matchResume
  },
  MYRESUME(state,myResume){
    state.myResume = myResume.resumeInfo
  },
  MYBASICRESUME(state,myResume){
    state.myBasicResume = myResume.resumeBaseInfo
  },
  MYCORERESUME(state,myResume){
    state.myCoreResume = myResume.resumeCoreInfo
  },
  CLEARRESUME(state){
    state.myResume={}
    state.myBasicResume={}
    state.myCoreResume={}
  },
  RESUMEID(state,resumeId){
    state.resumeId = resumeId.resumeId
  }
}
const actions = {
  async getHasResume({commit}){
    let result = await reqHasResume();
    if (result.code===20000){
      commit("HASRESUME",result.data)
    }
  },
  async getMatchResume({commit}){
    let result = await reqMatchResume();
    if (result.code===20000){
      commit("MATCHRESUME",result.data)
    }
  },
  async getMyResume({commit}){
    let result = await reqMyResume();
    if (result.code===20000){
      commit("MYRESUME",result.data)
      commit("MYBASICRESUME",result.data)
      commit("MYCORERESUME",result.data)
    }else {
      commit("CLEARRESUME")
    }
  },
  async getEditBasicResume({commit},resume){
    let result = await reqResumeBaseInfo(resume);
    if (result.code===20000){
      return 'ok'
    }else {
      return Promise.reject(new Error('false'))
    }
  },
  async getEditCoreResume({commit},resume){
    let result = await reqResumeCoreInfo(resume);
    if (result.code===20000){
      return 'ok'
    }else {
      return Promise.reject(new Error('false'))
    }
  },
  async getAddBasicResume({commit},resume){
    let result = await reqAddResumeBaseInfo(resume);
    if (result.code===20000){
      commit("RESUMEID",result.data)
    }else {
      return Promise.reject(new Error('false'))
    }
  },
  async getAddCoreResume({commit},resume){
    console.log(resume)
    let result = await reqAddResumeCoreInfo(resume.resumeId,resume.coreResume);
    if (result.code===20000){
      return 'ok'
    }else {
      return Promise.reject(new Error('false'))
    }
  },

}
const getters= {}
export default {
  state,
  mutations,
  actions,
  getters
}